/*
 * console.h
 *
 *  Created on: 2017年3月21日
 *      Author: zhikang.peng
 */

#ifndef OS_CONSOLE_H_
#define OS_CONSOLE_H_ 1

#include "sheet.h"
#include "timer.h"

struct CONSOLE {
	struct SHEET *sht;
	int cursor_x, cursor_y, cursor_c;
	struct TIMER *timer;
};

void cons_putstr(struct CONSOLE *cons, char *s);
void cons_putstrlen(struct CONSOLE *cons, char *s, int len);
struct CONSOLE cons_init(struct SHEET *sheet, int cursor_x, int cursor_y, int cursor_c);
void cons_newline(struct CONSOLE *cons);
void cons_putchar(struct CONSOLE *cons, int c, char move);
void cmd_mem(struct CONSOLE *cons, unsigned int memtotal);
void cmd_cls(struct CONSOLE *cons);
void cmd_dir(struct CONSOLE *cons);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal);
void console_task(struct SHEET *sheet, unsigned int memtotal);
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_cmd(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_langmode(struct CONSOLE *cons, char *cmdline);
void cmd_exit(struct CONSOLE *cons, int *fat);
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
int *system_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
int *inthandler0c(int *esp);
int *inthandler0d(int *esp);
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal);
void keywin_off(struct SHEET *key_win);
void keywin_on(struct SHEET *key_win);
void close_constask(struct TASK *task);
void close_console(struct SHEET *sht);
/**
 * 处理栈异常中断
 * esp内容
 * esp[0-7]为_asm_inthandler中pushad的结果
 * esp[9-9]为_asm_inthandler中push的结果
 * esp[10-15]为异常产生时cpu自动push的结果
 *
 * esp[0]= edi
 * esp[1]= esi
 * esp[2]= ebp
 * esp[3]= esp
 * esp[4]= ebx
 * esp[5]= edx
 * esp[6]= ecx
 * esp[7]= eax
 * esp[8]= ds
 * esp[9]= es
 * esp[10]= 错误编号(基本上市0)
 * esp[11]= eip
 * esp[12]= cs
 * esp[13]= eflags
 * esp[14]= esp (应用程序esp)
 * esp[15]= ss (应用程序ss)
 */
int *inthandler0c(int *esp);
int *inthandler0d(int *esp);

#endif /* OS_CONSOLE_H_ */
